package day02;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * 输入一个数学计算表达式，如:1+2
 * 然后输出计算后的结果:1+2=3
 * 这里计算表达式只计算一次即可，可以使用加减乘除任意一个,可以进行小数运算。
 * @author Bonnie
 *
 */
public class Test07 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.next();
        String[] str2 = str1.split("[+\\-*/]");
        String[] str3 = str1.split("\\d+(.\\d+)?");//负数问题
        ArrayList<Float> nums = new ArrayList<>();
        for (String s : str2){
            nums.add(changeFloat(s));
        }
        System.out.println(result(nums,str3));
    }
    public static float changeFloat(String str){
        String[] strs = str.split("\\.");
        boolean isDecimal = false;
        if (strs.length>1){
            isDecimal=true;
        }
        String s1 = strs[0];
        float num = 0;
        float flag = 0;
        for (int i = 0; i < s1.length(); i++) {
            flag = (float) ((s1.charAt(i) - 48) * Math.pow(10, s1.length() - 1 - i));
            num += flag;
        }
        if (isDecimal) {
            String s2 = strs[1];
            for (int i = 0; i < s2.length(); i++) {
                flag = (float) ((s2.charAt(i) - 48) * Math.pow(0.1, i + 1));
                num += flag;
            }
        }
        return num;
    }

    private static String result(ArrayList<Float> nums, String[] j){
        float result = nums.get(0);
        for(int i = 1;i<nums.size();i++){
            switch (j[i]){
                case "+":
                    result += nums.get(i);
                    break;
                case "-" :
                    result -= nums.get(i);
                    break;
                case "*" :
                    result *= nums.get(i);
                    break;
                case "/" :
                    result = result/nums.get(i);
                    break;
            }
        }
        DecimalFormat df = new DecimalFormat("0.0000");
        return df.format(result);
    }
}
